import axios from "axios";
import createLoading from "./createLoading.js";
const Axiosinstance = axios.create({
  baseURL:import.meta.env.VITE_API_BASE_URL,
  timeout: 10000,
});
let loading = null
// 添加请求拦截器
Axiosinstance.interceptors.request.use(function (config) {
  //为每一个请求添加请求实例loading
  config.loadingInstance = createLoading({
    text:'正在加载'
  })
    return config;
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  });
// 添加响应拦截器
Axiosinstance.interceptors.response.use(function (response) {
  const loadingInstance = response.config.loadingInstance
  if(loadingInstance){
    loadingInstance.cleanFn(10)
  }
    return response;
  }, function (error) {
    const loading = error?.config.loadingInstance
    loading.cleanFn(10)
    return Promise.reject(error);
  }); 
  export default Axiosinstance